package org.redr.canvas;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public abstract class InputSocket extends SignalSocket{
	
	private Boolean multiple;
	private Map<String, OutputSocket> connections = new HashMap<String, OutputSocket>();
	
	public InputSocket(RRW widget, String signalId, String n,
			boolean multi) {
		super(widget, signalId, n);
		multiple = multi;
	}
	
	public Boolean isMultiple()
	{
		return multiple;
	}

	public boolean canConnect(OutputSocket o) throws Exception {
		List<String> thisConnectionTypes = connectionTypes();
		List<String> oConnectionTypes = o.connectionTypes();
		// TODO Auto-generated method stub
		for (String s : thisConnectionTypes){
			for (String os : oConnectionTypes){
				if (s.equals(os)) return true;
			}
		}
		return false;
	}
	
	public void addConnection(OutputSocket out){
		connections.put(out.getWidgetId(), out);
	}

	public void takeData(Object object, String compatibleSignal, String widgetId) {
		Object convertedData = this.convertData(object, compatibleSignal);
		this.widget().dataInput(this.getSignalId(), convertedData, widgetId);
	}
	
	/**
	 * Implement this signal for all elements that you wish to convert.
	 * Must have a method for each connectionType in connectionTypes().
	 * @param data - Object
	 * @param connectionType - String
	 * @return convertedData - Object
	 */
	public abstract Object convertData(Object data, String connectionType);
}
